from faker import Faker
from selenium.webdriver.common.by import By
from class23test0515.page_object.basepage import BasePage
from class23test0515.until.log_until import logger


class ContactPage(BasePage):
    __ADD_BTN = '//i[text()="添加"]'
    __ADD_DEPARTMENT_BTN = '//a[text()="添加部门"]'
    __NAME_INPUT = '//input[@name="name"]'
    # 选择所属部门下拉框
    __CHOOSE_DROPBOX = '//span[text()="选择所属部门"]'
    __DEPARTMENT_NAME = '//span[text()="选择所属部门"]/../..//a[text()="saberpan"]'
    __SAVE_BTN = '//a[text()="确定"]'

    def add_member(self):
        """添加成员，返回AddMemberPage"""
        # 2.点击添加成员按钮
        logger.info("点击添加成员按钮")
        self.do_find(By.LINK_TEXT, "添加成员").click()
        from class23test0515.page_object.addmemberpage import AddMemberPage
        return AddMemberPage(self.driver)

    def add_department(self, department):
        """添加部门"""
        # 添加部门页面就在通讯录页面，所以没有新建Page
        logger.info("点击添加部门")
        self.do_find(By.XPATH, self.__ADD_BTN).click()
        self.do_find(By.XPATH, self.__ADD_DEPARTMENT_BTN).click()
        self.do_find(By.XPATH, self.__NAME_INPUT).send_keys(department)
        self.do_find(By.XPATH, self.__CHOOSE_DROPBOX).click()
        self.do_find(By.XPATH, self.__DEPARTMENT_NAME).click()
        self.do_find(By.XPATH, self.__SAVE_BTN).click()
        return ContactPage(self.driver)

    def gettip(self):
        """获取提示信息"""
        loc_tips = (By.ID, "js_tips")
        self.do_wait_element_locate(loc_tips)
        tips_value = self.do_find(loc_tips).text
        return tips_value
